package de.blitzcoder.cddatabase.gui.trackeditor;

import de.blitzcoder.cddatabase.data.Track;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;

/**
 *
 * @author blitzcoder
 */
public class TrackTable extends JTable {

    private static int[] COLUMNWIDTH = {30,-1,-1,50}; // -1 = not defined
    
    private TrackTableModel model;

    public TrackTable(int trackCount) {
        model = new TrackTableModel(trackCount);
        setModel(model);
        init();
    }
    
    public TrackTable(Track[] tracks) {
        model = new TrackTableModel(tracks);
        setModel(model);
        init();
    }
    
    public void addTrack() {
        model.addTrack();
    }
    
    public void removeTrack() {
        model.removeTrack();
    }

    public Track[] getTracks() {
        return getModel().getTracks();
    }
    
    @Override
    public TrackTableModel getModel() {
        return model;
    }

    private void init() {
        setDefaultRenderer(String.class, new TrackTableCellRenderer());

        int columnCount = getColumnModel().getColumnCount();
        for (int i=0;i<columnCount;i++)
            if (COLUMNWIDTH[i] != -1) {
                getColumnModel().getColumn(i).setMinWidth(COLUMNWIDTH[i]);
                getColumnModel().getColumn(i).setMaxWidth(COLUMNWIDTH[i]);
            }
        
        setCellSelectionEnabled(false);
        setRowSelectionAllowed(false);
    }

}
